<template>
  <div class="statistics-cards" v-if="statistics">
    <a-row :gutter="16">
      <a-col
        v-for="(stat, index) in statisticsData"
        :key="stat.key"
        :span="6"
        v-memo="[stat.value, stat.title]"
      >
        <a-card class="stat-card" :hoverable="true">
          <a-statistic
            :title="stat.title"
            :value="stat.value"
            :value-style="{ color: stat.color }"
            :prefix="stat.prefix"
          >
            <template #suffix v-if="stat.suffix">
              {{ stat.suffix }}
            </template>
          </a-statistic>
          <div class="stat-trend" v-if="stat.trend">
            <a-tag :color="stat.trend.color">
              {{ stat.trend.icon }} {{ stat.trend.text }}
            </a-tag>
          </div>
        </a-card>
      </a-col>
    </a-row>
  </div>
</template>

<script setup>
import { computed } from 'vue'

const props = defineProps({
  statistics: {
    type: Object,
    required: true
  }
})

// 计算属性：优化的统计数据格式化
const statisticsData = computed(() => [
  {
    key: 'total_tasks',
    title: '总任务数',
    value: props.statistics.total_tasks || 0,
    color: '#1890ff',
    prefix: '📊'
  },
  {
    key: 'active_tasks',
    title: '活跃任务',
    value: props.statistics.active_tasks || 0,
    color: '#52c41a',
    prefix: '🚀'
  },
  {
    key: 'successful_syncs_today',
    title: '今日成功同步',
    value: props.statistics.successful_syncs_today || 0,
    color: '#13c2c2',
    prefix: '✅'
  },
  {
    key: 'failed_syncs_today',
    title: '今日失败同步',
    value: props.statistics.failed_syncs_today || 0,
    color: '#ff4d4f',
    prefix: '❌',
    trend: props.statistics.failed_syncs_today > 0 ? {
      color: 'red',
      icon: '↑',
      text: '需要关注'
    } : null
  }
])
</script>

<style scoped>
.statistics-cards {
  margin-bottom: 16px;
}

.stat-card {
  text-align: center;
  transition: all 0.3s ease;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
}

.stat-trend {
  margin-top: 8px;
  font-size: 12px;
}

:deep(.ant-statistic-title) {
  font-size: 14px;
  color: #666;
  margin-bottom: 4px;
}

:deep(.ant-statistic-content) {
  font-size: 24px;
  font-weight: 600;
}

:deep(.ant-statistic-content-prefix) {
  margin-right: 8px;
}
</style>